//
//  EmoticonAttachment.swift
//  02-表情键盘
//
//  Created by  NorthCity on 15/11/15.
//  Copyright © 2015年  NorthCity. All rights reserved.
//

import UIKit

class EmoticonAttachment: NSTextAttachment {
    var chs:String?
  class func imageText(em:Emoticon,font:UIFont) -> NSAttributedString{
        
        //        1> 创建图像附件
        let attachment = EmoticonAttachment()
        attachment.image = UIImage(contentsOfFile: em.imagePath)
        attachment.chs = em.chs
        //        设置线高
        let lineHeight = font.lineHeight
        attachment.bounds = CGRect(x: 0, y: -4, width: lineHeight, height: lineHeight)
        
        let imageText = NSMutableAttributedString(attributedString: NSAttributedString(attachment: attachment))
        imageText.addAttribute(NSFontAttributeName, value: font, range: NSRange(location: 0, length: 1))

        return imageText
    }
}
